<?php
	session_start();
	require_once '../user.php'; 
	if (isset($_GET['un'])){$username = $_GET['un'];}
	if (isset($_GET['id'])){$idfoto = $_GET['id'];}
	
	if (isset($_GET["last"])) $before = $_GET["last"];
	else $before = 0;
	if (isset($_SESSION['username']))
	{
		$login = true;
		$loguname = $_SESSION["username"];
	}
	else{ $login = false; }
	require_once '../photo.php';
	$listcomment = photo::getComment($username,$idfoto);
	$nlistc = mysql_num_rows($listcomment);
	$npage = $nlistc%5==0?$nlistc/5:floor($nlistc/5+1); 
	if ($before==-1){$before=($npage-1)*5;}
	
	$nowpage = $before/5+1;
	$last = 0;
	//Bikin nomor halaman
	if ($npage>1)
	for ($i=1;$i<=$npage;$i++){
		if ($i == $nowpage){
			echo '<div class="numbox"  style="background-color:#999;">';
			echo '<a>'.$i.'</a>';
			echo '</div>';
		}
		else{
			echo '<div class="numbox  style="background-color:#999;color:#000;">';
			echo '<a class="biasa" href="javascript:void()" onclick="getComments(\''.$username.'\','.$idfoto.','.$last.');" >'.$i.'</a>';
			echo '</div>';
		}
		$last += 5;
	}
	echo '<br/>';
	$count = 0;	
	if ($nlistc!=0)	mysql_data_seek($listcomment,$before);
	while (($row = mysql_fetch_array($listcomment))&&$count<5){
		$count += 1;
?>
		<div class="boxcomment">
        <?php
        	if ($username==$loguname||user::isRoleAdmin($loguname)){
        ?>
			<div class="x" onclick="delComment('<?php echo $username;?>',<?php echo $row["IDFoto"];?>,<?php echo $row["IDKomentar"]; ?>,<?php echo floor($count/5);?>)"></div>
			<form name="delcomment<?php echo $row["IDKomentar"]; ?>" action="php/photoop.php" method="post">
				<input type="hidden" name="operation" value="delcomment"/>
				<input type="hidden" name="idfoto" value="<?php echo $row["IDFoto"]; ?>"/>
				<input type="hidden" name="komenname" value="<?php echo $row["Username"]; ?>"/>
				<input type="hidden" name="idcomment" value="<?php echo $row["IDKomentar"]; ?>"/>
			</form>
        <?php }		?>
			<div class="minava">
			<?php
				$avatarc = photo::getProfPicPath($row["Komentator"]);
				echo '<img class="minava" src="'.$avatarc.'" />'
			?>
			</div>
			<div class="commpl">
				<div style="text-align:left;padding-left:5px;"><a class="unameh3" href="profile.php?<?php echo $row["Komentator"];?>"><?php echo user::getName($row["Komentator"]);?></a></div>
				<div class="comment"><?php echo $row["Komentar"];?></div>
				<div class="commenttime"><?php 
				/*$nowdate = new DateTime();
				$m = $nowdate->getTimestamp()-$row["Postedon"]; 
				$date = new DateTime($m);*/
				echo $row["Postedon"]; 
				?></div>
			</div>
		</div>
<?php 
}
?>